home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / gdata / __init__.pyc (.txt) next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  32.2 KB  |  822 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Contains classes representing Google Data elements.
  5.  
  6.   Extends Atom classes to add Google Data specific elements.
  7. '''
  8. __author__ = 'api.jscudder (Jeffrey Scudder)'
  9. import os
  10. import atom
  11.  
  12. try:
  13.     from xml.etree import cElementTree as ElementTree
  14. except ImportError:
  15.     
  16.     try:
  17.         import cElementTree as ElementTree
  18.     except ImportError:
  19.         
  20.         try:
  21.             from xml.etree import ElementTree
  22.         except ImportError:
  23.             from elementtree import ElementTree
  24.         except:
  25.             None<EXCEPTION MATCH>ImportError
  26.         
  27.  
  28.         None<EXCEPTION MATCH>ImportError
  29.     
  30.  
  31.     None<EXCEPTION MATCH>ImportError
  32.  
  33. GDATA_NAMESPACE = 'http://schemas.google.com/g/2005'
  34. GDATA_TEMPLATE = '{http://schemas.google.com/g/2005}%s'
  35. OPENSEARCH_NAMESPACE = 'http://a9.com/-/spec/opensearchrss/1.0/'
  36. OPENSEARCH_TEMPLATE = '{http://a9.com/-/spec/opensearchrss/1.0/}%s'
  37. BATCH_NAMESPACE = 'http://schemas.google.com/gdata/batch'
  38. GACL_NAMESPACE = 'http://schemas.google.com/acl/2007'
  39. GACL_TEMPLATE = '{http://schemas.google.com/acl/2007}%s'
  40. BATCH_INSERT = 'insert'
  41. BATCH_UPDATE = 'update'
  42. BATCH_DELETE = 'delete'
  43. BATCH_QUERY = 'query'
  44.  
  45. class Error(Exception):
  46.     pass
  47.  
  48.  
  49. class MissingRequiredParameters(Error):
  50.     pass
  51.  
  52.  
  53. class MediaSource(object):
  54.     '''GData Entries can refer to media sources, so this class provides a
  55.   place to store references to these objects along with some metadata.
  56.   '''
  57.     
  58.     def __init__(self, file_handle = None, content_type = None, content_length = None, file_path = None, file_name = None):
  59.         '''Creates an object of type MediaSource.
  60.  
  61.     Args:
  62.       file_handle: A file handle pointing to the file to be encapsulated in the
  63.                    MediaSource
  64.       content_type: string The MIME type of the file. Required if a file_handle
  65.                     is given.
  66.       content_length: int The size of the file. Required if a file_handle is
  67.                       given.
  68.       file_path: string (optional) A full path name to the file. Used in
  69.                     place of a file_handle.
  70.       file_name: string The name of the file without any path information.
  71.                  Required if a file_handle is given.
  72.     '''
  73.         self.file_handle = file_handle
  74.         self.content_type = content_type
  75.         self.content_length = content_length
  76.         self.file_name = file_name
  77.         if file_handle is None and content_type is not None and file_path is not None:
  78.             self.setFile(file_path, content_type)
  79.         
  80.  
  81.     
  82.     def setFile(self, file_name, content_type):
  83.         '''A helper function which can create a file handle from a given filename
  84.     and set the content type and length all at once.
  85.  
  86.     Args:
  87.       file_name: string The path and file name to the file containing the media
  88.       content_type: string A MIME type representing the type of the media
  89.     '''
  90.         self.file_handle = open(file_name, 'rb')
  91.         self.content_type = content_type
  92.         self.content_length = os.path.getsize(file_name)
  93.         self.file_name = os.path.basename(file_name)
  94.  
  95.  
  96.  
  97. class LinkFinder(atom.LinkFinder):
  98.     '''An "interface" providing methods to find link elements
  99.  
  100.   GData Entry elements often contain multiple links which differ in the rel
  101.   attribute or content type. Often, developers are interested in a specific
  102.   type of link so this class provides methods to find specific classes of
  103.   links.
  104.  
  105.   This class is used as a mixin in GData entries.
  106.   '''
  107.     
  108.     def GetSelfLink(self):
  109.         """Find the first link with rel set to 'self'
  110.  
  111.     Returns:
  112.       An atom.Link or none if none of the links had rel equal to 'self'
  113.     """
  114.         for a_link in self.link:
  115.             if a_link.rel == 'self':
  116.                 return a_link
  117.         
  118.  
  119.     
  120.     def GetEditLink(self):
  121.         for a_link in self.link:
  122.             if a_link.rel == 'edit':
  123.                 return a_link
  124.         
  125.  
  126.     
  127.     def GetEditMediaLink(self):
  128.         '''The Picasa API mistakenly returns media-edit rather than edit-media, but
  129.     this may change soon.
  130.     '''
  131.         for a_link in self.link:
  132.             if a_link.rel == 'edit-media':
  133.                 return a_link
  134.             if a_link.rel == 'media-edit':
  135.                 return a_link
  136.         
  137.  
  138.     
  139.     def GetHtmlLink(self):
  140.         '''Find the first link with rel of alternate and type of text/html
  141.  
  142.     Returns:
  143.       An atom.Link or None if no links matched
  144.     '''
  145.         for a_link in self.link:
  146.             if a_link.rel == 'alternate' and a_link.type == 'text/html':
  147.                 return a_link
  148.         
  149.  
  150.     
  151.     def GetPostLink(self):
  152.         '''Get a link containing the POST target URL.
  153.     
  154.     The POST target URL is used to insert new entries.
  155.  
  156.     Returns:
  157.       A link object with a rel matching the POST type.
  158.     '''
  159.         for a_link in self.link:
  160.             if a_link.rel == 'http://schemas.google.com/g/2005#post':
  161.                 return a_link
  162.         
  163.  
  164.     
  165.     def GetAclLink(self):
  166.         for a_link in self.link:
  167.             if a_link.rel == 'http://schemas.google.com/acl/2007#accessControlList':
  168.                 return a_link
  169.         
  170.  
  171.     
  172.     def GetFeedLink(self):
  173.         for a_link in self.link:
  174.             if a_link.rel == 'http://schemas.google.com/g/2005#feed':
  175.                 return a_link
  176.         
  177.  
  178.     
  179.     def GetNextLink(self):
  180.         for a_link in self.link:
  181.             if a_link.rel == 'next':
  182.                 return a_link
  183.         
  184.  
  185.     
  186.     def GetPrevLink(self):
  187.         for a_link in self.link:
  188.             if a_link.rel == 'previous':
  189.                 return a_link
  190.         
  191.  
  192.  
  193.  
  194. class TotalResults(atom.AtomBase):
  195.     '''opensearch:TotalResults for a GData feed'''
  196.     _tag = 'totalResults'
  197.     _namespace = OPENSEARCH_NAMESPACE
  198.     _children = atom.AtomBase._children.copy()
  199.     _attributes = atom.AtomBase._attributes.copy()
  200.     
  201.     def __init__(self, extension_elements = None, extension_attributes = None, text = None):
  202.         self.text = text
  203.         if not extension_elements:
  204.             pass
  205.         self.extension_elements = []
  206.         if not extension_attributes:
  207.             pass
  208.         self.extension_attributes = { }
  209.  
  210.  
  211.  
  212. def TotalResultsFromString(xml_string):
  213.     return atom.CreateClassFromXMLString(TotalResults, xml_string)
  214.  
  215.  
  216. class StartIndex(atom.AtomBase):
  217.     '''The opensearch:startIndex element in GData feed'''
  218.     _tag = 'startIndex'
  219.     _namespace = OPENSEARCH_NAMESPACE
  220.     _children = atom.AtomBase._children.copy()
  221.     _attributes = atom.AtomBase._attributes.copy()
  222.     
  223.     def __init__(self, extension_elements = None, extension_attributes = None, text = None):
  224.         self.text = text
  225.         if not extension_elements:
  226.             pass
  227.         self.extension_elements = []
  228.         if not extension_attributes:
  229.             pass
  230.         self.extension_attributes = { }
  231.  
  232.  
  233.  
  234. def StartIndexFromString(xml_string):
  235.     return atom.CreateClassFromXMLString(StartIndex, xml_string)
  236.  
  237.  
  238. class ItemsPerPage(atom.AtomBase):
  239.     '''The opensearch:itemsPerPage element in GData feed'''
  240.     _tag = 'itemsPerPage'
  241.     _namespace = OPENSEARCH_NAMESPACE
  242.     _children = atom.AtomBase._children.copy()
  243.     _attributes = atom.AtomBase._attributes.copy()
  244.     
  245.     def __init__(self, extension_elements = None, extension_attributes = None, text = None):
  246.         self.text = text
  247.         if not extension_elements:
  248.             pass
  249.         self.extension_elements = []
  250.         if not extension_attributes:
  251.             pass
  252.         self.extension_attributes = { }
  253.  
  254.  
  255.  
  256. def ItemsPerPageFromString(xml_string):
  257.     return atom.CreateClassFromXMLString(ItemsPerPage, xml_string)
  258.  
  259.  
  260. class ExtendedProperty(atom.AtomBase):
  261.     '''The Google Data extendedProperty element.
  262.   
  263.   Used to store arbitrary key-value information specific to your
  264.   application. The value can either be a text string stored as an XML 
  265.   attribute (.value), or an XML node (XmlBlob) as a child element.
  266.  
  267.   This element is used in the Google Calendar data API and the Google
  268.   Contacts data API.
  269.   '''
  270.     _tag = 'extendedProperty'
  271.     _namespace = GDATA_NAMESPACE
  272.     _children = atom.AtomBase._children.copy()
  273.     _attributes = atom.AtomBase._attributes.copy()
  274.     _attributes['name'] = 'name'
  275.     _attributes['value'] = 'value'
  276.     
  277.     def __init__(self, name = None, value = None, extension_elements = None, extension_attributes = None, text = None):
  278.         self.name = name
  279.         self.value = value
  280.         self.text = text
  281.         if not extension_elements:
  282.             pass
  283.         self.extension_elements = []
  284.         if not extension_attributes:
  285.             pass
  286.         self.extension_attributes = { }
  287.  
  288.     
  289.     def GetXmlBlobExtensionElement(self):
  290.         """Returns the XML blob as an atom.ExtensionElement.
  291.     
  292.     Returns:
  293.       An atom.ExtensionElement representing the blob's XML, or None if no
  294.       blob was set.
  295.     """
  296.         if len(self.extension_elements) < 1:
  297.             return None
  298.         return self.extension_elements[0]
  299.  
  300.     
  301.     def GetXmlBlobString(self):
  302.         """Returns the XML blob as a string.
  303.  
  304.     Returns:
  305.       A string containing the blob's XML, or None if no blob was set.
  306.     """
  307.         blob = self.GetXmlBlobExtensionElement()
  308.         if blob:
  309.             return blob.ToString()
  310.  
  311.     
  312.     def SetXmlBlob(self, blob):
  313.         '''Sets the contents of the extendedProperty to XML as a child node.
  314.  
  315.     Since the extendedProperty is only allowed one child element as an XML
  316.     blob, setting the XML blob will erase any preexisting extension elements
  317.     in this object.
  318.  
  319.     Args:
  320.       blob: str, ElementTree Element or atom.ExtensionElement representing
  321.             the XML blob stored in the extendedProperty.
  322.     '''
  323.         self.extension_elements = []
  324.         if isinstance(blob, atom.ExtensionElement):
  325.             self.extension_elements.append(blob)
  326.         elif ElementTree.iselement(blob):
  327.             self.extension_elements.append(atom._ExtensionElementFromElementTree(blob))
  328.         else:
  329.             self.extension_elements.append(atom.ExtensionElementFromString(blob))
  330.  
  331.  
  332.  
  333. def ExtendedPropertyFromString(xml_string):
  334.     return atom.CreateClassFromXMLString(ExtendedProperty, xml_string)
  335.  
  336.  
  337. class GDataEntry(atom.Entry, LinkFinder):
  338.     '''Extends Atom Entry to provide data processing'''
  339.     _tag = atom.Entry._tag
  340.     _namespace = atom.Entry._namespace
  341.     _children = atom.Entry._children.copy()
  342.     _attributes = atom.Entry._attributes.copy()
  343.     
  344.     def __GetId(self):
  345.         return self._GDataEntry__id
  346.  
  347.     
  348.     def __SetId(self, id):
  349.         self._GDataEntry__id = id
  350.         if id is not None and id.text is not None:
  351.             self._GDataEntry__id.text = id.text.strip()
  352.         
  353.  
  354.     id = property(__GetId, __SetId)
  355.     
  356.     def IsMedia(self):
  357.         '''Determines whether or not an entry is a GData Media entry.
  358.     '''
  359.         if self.GetEditMediaLink():
  360.             return True
  361.         return False
  362.  
  363.     
  364.     def GetMediaURL(self):
  365.         '''Returns the URL to the media content, if the entry is a media entry.
  366.     Otherwise returns None.
  367.     '''
  368.         if not self.IsMedia():
  369.             return None
  370.         return self.content.src
  371.  
  372.  
  373.  
  374. def GDataEntryFromString(xml_string):
  375.     '''Creates a new GDataEntry instance given a string of XML.'''
  376.     return atom.CreateClassFromXMLString(GDataEntry, xml_string)
  377.  
  378.  
  379. class GDataFeed(atom.Feed, LinkFinder):
  380.     '''A Feed from a GData service'''
  381.     _tag = 'feed'
  382.     _namespace = atom.ATOM_NAMESPACE
  383.     _children = atom.Feed._children.copy()
  384.     _attributes = atom.Feed._attributes.copy()
  385.     _children['{%s}totalResults' % OPENSEARCH_NAMESPACE] = ('total_results', TotalResults)
  386.     _children['{%s}startIndex' % OPENSEARCH_NAMESPACE] = ('start_index', StartIndex)
  387.     _children['{%s}itemsPerPage' % OPENSEARCH_NAMESPACE] = ('items_per_page', ItemsPerPage)
  388.     _children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [
  389.         GDataEntry])
  390.     
  391.     def __GetId(self):
  392.         return self._GDataFeed__id
  393.  
  394.     
  395.     def __SetId(self, id):
  396.         self._GDataFeed__id = id
  397.         if id is not None and id.text is not None:
  398.             self._GDataFeed__id.text = id.text.strip()
  399.         
  400.  
  401.     id = property(__GetId, __SetId)
  402.     
  403.     def __GetGenerator(self):
  404.         return self._GDataFeed__generator
  405.  
  406.     
  407.     def __SetGenerator(self, generator):
  408.         self._GDataFeed__generator = generator
  409.         if generator is not None:
  410.             self._GDataFeed__generator.text = generator.text.strip()
  411.         
  412.  
  413.     generator = property(__GetGenerator, __SetGenerator)
  414.     
  415.     def __init__(self, author = None, category = None, contributor = None, generator = None, icon = None, atom_id = None, link = None, logo = None, rights = None, subtitle = None, title = None, updated = None, entry = None, total_results = None, start_index = None, items_per_page = None, extension_elements = None, extension_attributes = None, text = None):
  416.         """Constructor for Source
  417.     
  418.     Args:
  419.       author: list (optional) A list of Author instances which belong to this
  420.           class.
  421.       category: list (optional) A list of Category instances
  422.       contributor: list (optional) A list on Contributor instances
  423.       generator: Generator (optional) 
  424.       icon: Icon (optional) 
  425.       id: Id (optional) The entry's Id element
  426.       link: list (optional) A list of Link instances
  427.       logo: Logo (optional) 
  428.       rights: Rights (optional) The entry's Rights element
  429.       subtitle: Subtitle (optional) The entry's subtitle element
  430.       title: Title (optional) the entry's title element
  431.       updated: Updated (optional) the entry's updated element
  432.       entry: list (optional) A list of the Entry instances contained in the 
  433.           feed.
  434.       text: String (optional) The text contents of the element. This is the 
  435.           contents of the Entry's XML text node. 
  436.           (Example: <foo>This is the text</foo>)
  437.       extension_elements: list (optional) A list of ExtensionElement instances
  438.           which are children of this element.
  439.       extension_attributes: dict (optional) A dictionary of strings which are 
  440.           the values for additional XML attributes of this element.
  441.     """
  442.         if not author:
  443.             pass
  444.         self.author = []
  445.         if not category:
  446.             pass
  447.         self.category = []
  448.         if not contributor:
  449.             pass
  450.         self.contributor = []
  451.         self.generator = generator
  452.         self.icon = icon
  453.         self.id = atom_id
  454.         if not link:
  455.             pass
  456.         self.link = []
  457.         self.logo = logo
  458.         self.rights = rights
  459.         self.subtitle = subtitle
  460.         self.title = title
  461.         self.updated = updated
  462.         if not entry:
  463.             pass
  464.         self.entry = []
  465.         self.total_results = total_results
  466.         self.start_index = start_index
  467.         self.items_per_page = items_per_page
  468.         self.text = text
  469.         if not extension_elements:
  470.             pass
  471.         self.extension_elements = []
  472.         if not extension_attributes:
  473.             pass
  474.         self.extension_attributes = { }
  475.  
  476.  
  477.  
  478. def GDataFeedFromString(xml_string):
  479.     return atom.CreateClassFromXMLString(GDataFeed, xml_string)
  480.  
  481.  
  482. class BatchId(atom.AtomBase):
  483.     _tag = 'id'
  484.     _namespace = BATCH_NAMESPACE
  485.     _children = atom.AtomBase._children.copy()
  486.     _attributes = atom.AtomBase._attributes.copy()
  487.  
  488.  
  489. def BatchIdFromString(xml_string):
  490.     return atom.CreateClassFromXMLString(BatchId, xml_string)
  491.  
  492.  
  493. class BatchOperation(atom.AtomBase):
  494.     _tag = 'operation'
  495.     _namespace = BATCH_NAMESPACE
  496.     _children = atom.AtomBase._children.copy()
  497.     _attributes = atom.AtomBase._attributes.copy()
  498.     _attributes['type'] = 'type'
  499.     
  500.     def __init__(self, op_type = None, extension_elements = None, extension_attributes = None, text = None):
  501.         self.type = op_type
  502.         atom.AtomBase.__init__(self, extension_elements = extension_elements, extension_attributes = extension_attributes, text = text)
  503.  
  504.  
  505.  
  506. def BatchOperationFromString(xml_string):
  507.     return atom.CreateClassFromXMLString(BatchOperation, xml_string)
  508.  
  509.  
  510. class BatchStatus(atom.AtomBase):
  511.     '''The batch:status element present in a batch response entry.
  512.   
  513.   A status element contains the code (HTTP response code) and 
  514.   reason as elements. In a single request these fields would
  515.   be part of the HTTP response, but in a batch request each
  516.   Entry operation has a corresponding Entry in the response
  517.   feed which includes status information.
  518.  
  519.   See http://code.google.com/apis/gdata/batch.html#Handling_Errors
  520.   '''
  521.     _tag = 'status'
  522.     _namespace = BATCH_NAMESPACE
  523.     _children = atom.AtomBase._children.copy()
  524.     _attributes = atom.AtomBase._attributes.copy()
  525.     _attributes['code'] = 'code'
  526.     _attributes['reason'] = 'reason'
  527.     _attributes['content-type'] = 'content_type'
  528.     
  529.     def __init__(self, code = None, reason = None, content_type = None, extension_elements = None, extension_attributes = None, text = None):
  530.         self.code = code
  531.         self.reason = reason
  532.         self.content_type = content_type
  533.         atom.AtomBase.__init__(self, extension_elements = extension_elements, extension_attributes = extension_attributes, text = text)
  534.  
  535.  
  536.  
  537. def BatchStatusFromString(xml_string):
  538.     return atom.CreateClassFromXMLString(BatchStatus, xml_string)
  539.  
  540.  
  541. class BatchEntry(GDataEntry):
  542.     '''An atom:entry for use in batch requests.
  543.  
  544.   The BatchEntry contains additional members to specify the operation to be
  545.   performed on this entry and a batch ID so that the server can reference
  546.   individual operations in the response feed. For more information, see:
  547.   http://code.google.com/apis/gdata/batch.html
  548.   '''
  549.     _tag = GDataEntry._tag
  550.     _namespace = GDataEntry._namespace
  551.     _children = GDataEntry._children.copy()
  552.     _children['{%s}operation' % BATCH_NAMESPACE] = ('batch_operation', BatchOperation)
  553.     _children['{%s}id' % BATCH_NAMESPACE] = ('batch_id', BatchId)
  554.     _children['{%s}status' % BATCH_NAMESPACE] = ('batch_status', BatchStatus)
  555.     _attributes = GDataEntry._attributes.copy()
  556.     
  557.     def __init__(self, author = None, category = None, content = None, contributor = None, atom_id = None, link = None, published = None, rights = None, source = None, summary = None, control = None, title = None, updated = None, batch_operation = None, batch_id = None, batch_status = None, extension_elements = None, extension_attributes = None, text = None):
  558.         self.batch_operation = batch_operation
  559.         self.batch_id = batch_id
  560.         self.batch_status = batch_status
  561.         GDataEntry.__init__(self, author = author, category = category, content = content, contributor = contributor, atom_id = atom_id, link = link, published = published, rights = rights, source = source, summary = summary, control = control, title = title, updated = updated, extension_elements = extension_elements, extension_attributes = extension_attributes, text = text)
  562.  
  563.  
  564.  
  565. def BatchEntryFromString(xml_string):
  566.     return atom.CreateClassFromXMLString(BatchEntry, xml_string)
  567.  
  568.  
  569. class BatchInterrupted(atom.AtomBase):
  570.     '''The batch:interrupted element sent if batch request was interrupted.
  571.   
  572.   Only appears in a feed if some of the batch entries could not be processed.
  573.   See: http://code.google.com/apis/gdata/batch.html#Handling_Errors
  574.   '''
  575.     _tag = 'interrupted'
  576.     _namespace = BATCH_NAMESPACE
  577.     _children = atom.AtomBase._children.copy()
  578.     _attributes = atom.AtomBase._attributes.copy()
  579.     _attributes['reason'] = 'reason'
  580.     _attributes['success'] = 'success'
  581.     _attributes['failures'] = 'failures'
  582.     _attributes['parsed'] = 'parsed'
  583.     
  584.     def __init__(self, reason = None, success = None, failures = None, parsed = None, extension_elements = None, extension_attributes = None, text = None):
  585.         self.reason = reason
  586.         self.success = success
  587.         self.failures = failures
  588.         self.parsed = parsed
  589.         atom.AtomBase.__init__(self, extension_elements = extension_elements, extension_attributes = extension_attributes, text = text)
  590.  
  591.  
  592.  
  593. def BatchInterruptedFromString(xml_string):
  594.     return atom.CreateClassFromXMLString(BatchInterrupted, xml_string)
  595.  
  596.  
  597. class BatchFeed(GDataFeed):
  598.     '''A feed containing a list of batch request entries.'''
  599.     _tag = GDataFeed._tag
  600.     _namespace = GDataFeed._namespace
  601.     _children = GDataFeed._children.copy()
  602.     _attributes = GDataFeed._attributes.copy()
  603.     _children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [
  604.         BatchEntry])
  605.     _children['{%s}interrupted' % BATCH_NAMESPACE] = ('interrupted', BatchInterrupted)
  606.     
  607.     def __init__(self, author = None, category = None, contributor = None, generator = None, icon = None, atom_id = None, link = None, logo = None, rights = None, subtitle = None, title = None, updated = None, entry = None, total_results = None, start_index = None, items_per_page = None, interrupted = None, extension_elements = None, extension_attributes = None, text = None):
  608.         self.interrupted = interrupted
  609.         GDataFeed.__init__(self, author = author, category = category, contributor = contributor, generator = generator, icon = icon, atom_id = atom_id, link = link, logo = logo, rights = rights, subtitle = subtitle, title = title, updated = updated, entry = entry, total_results = total_results, start_index = start_index, items_per_page = items_per_page, extension_elements = extension_elements, extension_attributes = extension_attributes, text = text)
  610.  
  611.     
  612.     def AddBatchEntry(self, entry = None, id_url_string = None, batch_id_string = None, operation_string = None):
  613.         """Logic for populating members of a BatchEntry and adding to the feed.
  614.  
  615.     
  616.     If the entry is not a BatchEntry, it is converted to a BatchEntry so
  617.     that the batch specific members will be present. 
  618.  
  619.     The id_url_string can be used in place of an entry if the batch operation
  620.     applies to a URL. For example query and delete operations require just
  621.     the URL of an entry, no body is sent in the HTTP request. If an
  622.     id_url_string is sent instead of an entry, a BatchEntry is created and
  623.     added to the feed.
  624.  
  625.     This method also assigns the desired batch id to the entry so that it 
  626.     can be referenced in the server's response. If the batch_id_string is
  627.     None, this method will assign a batch_id to be the index at which this
  628.     entry will be in the feed's entry list.
  629.     
  630.     Args:
  631.       entry: BatchEntry, atom.Entry, or another Entry flavor (optional) The
  632.           entry which will be sent to the server as part of the batch request.
  633.           The item must have a valid atom id so that the server knows which 
  634.           entry this request references.
  635.       id_url_string: str (optional) The URL of the entry to be acted on. You
  636.           can find this URL in the text member of the atom id for an entry.
  637.           If an entry is not sent, this id will be used to construct a new
  638.           BatchEntry which will be added to the request feed.
  639.       batch_id_string: str (optional) The batch ID to be used to reference
  640.           this batch operation in the results feed. If this parameter is None,
  641.           the current length of the feed's entry array will be used as a
  642.           count. Note that batch_ids should either always be specified or
  643.           never, mixing could potentially result in duplicate batch ids.
  644.       operation_string: str (optional) The desired batch operation which will
  645.           set the batch_operation.type member of the entry. Options are
  646.           'insert', 'update', 'delete', and 'query'
  647.     
  648.     Raises:
  649.       MissingRequiredParameters: Raised if neither an id_ url_string nor an
  650.           entry are provided in the request.
  651.  
  652.     Returns:
  653.       The added entry.
  654.     """
  655.         if entry is None and id_url_string is None:
  656.             raise MissingRequiredParameters('supply either an entry or URL string')
  657.         id_url_string is None
  658.         if entry is None and id_url_string is not None:
  659.             entry = BatchEntry(atom_id = atom.Id(text = id_url_string))
  660.         
  661.         if batch_id_string is not None:
  662.             entry.batch_id = BatchId(text = batch_id_string)
  663.         elif entry.batch_id is None or entry.batch_id.text is None:
  664.             entry.batch_id = BatchId(text = str(len(self.entry)))
  665.         
  666.         if operation_string is not None:
  667.             entry.batch_operation = BatchOperation(op_type = operation_string)
  668.         
  669.         self.entry.append(entry)
  670.         return entry
  671.  
  672.     
  673.     def AddInsert(self, entry, batch_id_string = None):
  674.         """Add an insert request to the operations in this batch request feed.
  675.  
  676.     If the entry doesn't yet have an operation or a batch id, these will
  677.     be set to the insert operation and a batch_id specified as a parameter.
  678.  
  679.     Args:
  680.       entry: BatchEntry The entry which will be sent in the batch feed as an
  681.           insert request.
  682.       batch_id_string: str (optional) The batch ID to be used to reference
  683.           this batch operation in the results feed. If this parameter is None,
  684.           the current length of the feed's entry array will be used as a
  685.           count. Note that batch_ids should either always be specified or
  686.           never, mixing could potentially result in duplicate batch ids.
  687.     """
  688.         entry = self.AddBatchEntry(entry = entry, batch_id_string = batch_id_string, operation_string = BATCH_INSERT)
  689.  
  690.     
  691.     def AddUpdate(self, entry, batch_id_string = None):
  692.         """Add an update request to the list of batch operations in this feed.
  693.  
  694.     Sets the operation type of the entry to insert if it is not already set
  695.     and assigns the desired batch id to the entry so that it can be 
  696.     referenced in the server's response.
  697.  
  698.     Args:
  699.       entry: BatchEntry The entry which will be sent to the server as an
  700.           update (HTTP PUT) request. The item must have a valid atom id
  701.           so that the server knows which entry to replace.
  702.       batch_id_string: str (optional) The batch ID to be used to reference
  703.           this batch operation in the results feed. If this parameter is None,
  704.           the current length of the feed's entry array will be used as a
  705.           count. See also comments for AddInsert.
  706.     """
  707.         entry = self.AddBatchEntry(entry = entry, batch_id_string = batch_id_string, operation_string = BATCH_UPDATE)
  708.  
  709.     
  710.     def AddDelete(self, url_string = None, entry = None, batch_id_string = None):
  711.         '''Adds a delete request to the batch request feed.
  712.  
  713.     This method takes either the url_string which is the atom id of the item
  714.     to be deleted, or the entry itself. The atom id of the entry must be 
  715.     present so that the server knows which entry should be deleted.
  716.  
  717.     Args:
  718.       url_string: str (optional) The URL of the entry to be deleted. You can
  719.          find this URL in the text member of the atom id for an entry. 
  720.       entry: BatchEntry (optional) The entry to be deleted.
  721.       batch_id_string: str (optional)
  722.  
  723.     Raises:
  724.       MissingRequiredParameters: Raised if neither a url_string nor an entry 
  725.           are provided in the request. 
  726.     '''
  727.         entry = self.AddBatchEntry(entry = entry, id_url_string = url_string, batch_id_string = batch_id_string, operation_string = BATCH_DELETE)
  728.  
  729.     
  730.     def AddQuery(self, url_string = None, entry = None, batch_id_string = None):
  731.         '''Adds a query request to the batch request feed.
  732.  
  733.     This method takes either the url_string which is the query URL 
  734.     whose results will be added to the result feed. The query URL will
  735.     be encapsulated in a BatchEntry, and you may pass in the BatchEntry
  736.     with a query URL instead of sending a url_string.
  737.  
  738.     Args:
  739.       url_string: str (optional)
  740.       entry: BatchEntry (optional)
  741.       batch_id_string: str (optional)
  742.  
  743.     Raises:
  744.       MissingRequiredParameters
  745.     '''
  746.         entry = self.AddBatchEntry(entry = entry, id_url_string = url_string, batch_id_string = batch_id_string, operation_string = BATCH_QUERY)
  747.  
  748.     
  749.     def GetBatchLink(self):
  750.         for link in self.link:
  751.             if link.rel == 'http://schemas.google.com/g/2005#batch':
  752.                 return link
  753.         
  754.  
  755.  
  756.  
  757. def BatchFeedFromString(xml_string):
  758.     return atom.CreateClassFromXMLString(BatchFeed, xml_string)
  759.  
  760.  
  761. class EntryLink(atom.AtomBase):
  762.     '''The gd:entryLink element'''
  763.     _tag = 'entryLink'
  764.     _namespace = GDATA_NAMESPACE
  765.     _children = atom.AtomBase._children.copy()
  766.     _attributes = atom.AtomBase._attributes.copy()
  767.     _children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', GDataEntry)
  768.     _attributes['rel'] = 'rel'
  769.     _attributes['readOnly'] = 'read_only'
  770.     _attributes['href'] = 'href'
  771.     
  772.     def __init__(self, href = None, read_only = None, rel = None, entry = None, extension_elements = None, extension_attributes = None, text = None):
  773.         self.href = href
  774.         self.read_only = read_only
  775.         self.rel = rel
  776.         self.entry = entry
  777.         self.text = text
  778.         if not extension_elements:
  779.             pass
  780.         self.extension_elements = []
  781.         if not extension_attributes:
  782.             pass
  783.         self.extension_attributes = { }
  784.  
  785.  
  786.  
  787. def EntryLinkFromString(xml_string):
  788.     return atom.CreateClassFromXMLString(EntryLink, xml_string)
  789.  
  790.  
  791. class FeedLink(atom.AtomBase):
  792.     '''The gd:feedLink element'''
  793.     _tag = 'feedLink'
  794.     _namespace = GDATA_NAMESPACE
  795.     _children = atom.AtomBase._children.copy()
  796.     _attributes = atom.AtomBase._attributes.copy()
  797.     _children['{%s}feed' % atom.ATOM_NAMESPACE] = ('feed', GDataFeed)
  798.     _attributes['rel'] = 'rel'
  799.     _attributes['readOnly'] = 'read_only'
  800.     _attributes['countHint'] = 'count_hint'
  801.     _attributes['href'] = 'href'
  802.     
  803.     def __init__(self, count_hint = None, href = None, read_only = None, rel = None, feed = None, extension_elements = None, extension_attributes = None, text = None):
  804.         self.count_hint = count_hint
  805.         self.href = href
  806.         self.read_only = read_only
  807.         self.rel = rel
  808.         self.feed = feed
  809.         self.text = text
  810.         if not extension_elements:
  811.             pass
  812.         self.extension_elements = []
  813.         if not extension_attributes:
  814.             pass
  815.         self.extension_attributes = { }
  816.  
  817.  
  818.  
  819. def FeedLinkFromString(xml_string):
  820.     return atom.CreateClassFromXMLString(EntryLink, xml_string)
  821.  
  822.